package se.teamscape.client.view;

import java.util.List;

import se.teamscape.client.presenter.ListModelsPresenter;
import se.teamscape.shared.model.Model;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Hyperlink;

/**
 * Generic view for listing models by display name
 * and creating hyperlinks with place tokens.
 * 
 * @author Andreas Borglin
 * 
 */
public class ListModelsView extends BaseView implements ListModelsPresenter.Display {

    private FlexTable mTable;
    private FlowPanel mPanel;

    public ListModelsView() {
    }

    @Override
    public void init() {
        mTable = new FlexTable();
        mPanel = new FlowPanel();

        mPanel.add(mTable);

        initWidget(mPanel);
    }

    @Override
    public void setData(List<Model> models, List<String> places) {

        int row = 0, columm = 0;
        for (Model model : models) {
            Hyperlink link = new Hyperlink();
            link.setText(model.getDisplayName());
            if (places != null && places.size() > row) {
                link.setTargetHistoryToken(places.get(row));
            }
            mTable.setWidget(row++, columm, link);
        }

    }

}
